package cn.lil.servlet;

import cn.lil.dao.BearingDao;
import cn.lil.dao.UserDao;
import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;

@WebServlet(name = "UserListDel", value = "/UserListDel")
public class UserListDel extends HttpServlet {
    private BearingDao bDao = new BearingDao();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int id = Integer.parseInt(request.getParameter("id"));
        try {
            bDao.deleteUser(id);
            RequestDispatcher dispatcher = request.getRequestDispatcher("/BearingServlet");
            dispatcher.forward(request, response);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
